package com.yiweikeji.project.core;

/**
 * 响应码枚举，参考HTTP状态码的语义
 */
public enum ResultCode {
    /**
     * 系统错误
     */
    SUCCESS("200","成功"),//成功
    FAIL("400","失败"),//失败
    UNAUTHORIZED("401","未认证（签名错误）"),//未认证（签名错误）
    NOT_FOUND("404","接口不存在"),//接口不存在
    INTERNAL_SERVER_ERROR("500","服务器内部错误"),
    PERMISSION_NOT_HAS("409","没有操作权限"),
    BACKSTAGE_IS_ERROR("501","网关异常"),
    
    /**
     * 业务错误
     */
    OBJECT_IS_NULL("6000","对象不能为空"),
    ID_IS_NULL("6001","对象ID不能为空"),
    CODE_IS_NULL("6002","编号不能为空"),
    NAME_IS_NULL("6003","名称不能为空"),
    SEQ_IS_NULL("6004","排序不能为空"),
    LEVEL_IS_NULL("6005","级别不能为空"),
    USERID_IS_NULL("6006","用户id不能为空"),
    RESULT_IS_NULL("6007","查询结果为空"),
    TYPE_IS_NULL("6008","查询结果为空"),
    SQL_ERROR("6009","数据库异常"),
    IDENTITY_IS_NULL("6010","身份证不能为空"),
    CUSTOMERID_IS_NULL("6011","客户号不能为空"),
    CUSTOMERID_IS_ERROR("6012","未查询到用户信息"),
    SELECT_IS_ERROR("6013","数据异常查询失败，请联系检查用户信息"),
    IDENTITYUPKEY_IS_ERROR("6014","身份证正面照片key不能为空"),
    CODE_IS_INVALID("6015","验证码无效"),
    TOKEN_IS_NULL("6016","TOKEN不能为空"),

    

    
    
    ;//服务器内部错误

    private final String code;   //状态码
    private final String message;

    ResultCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String code() {
        return code;
    }

    public String message() {
        return message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    /**
     * 通过状态码获取ENUM的名字
     * @param code
     * @return
     */
    public static ResultCode getEnumByStatusCode(String code) {
        for (ResultCode p : ResultCode.values()) {
            if (p.code().equalsIgnoreCase(code)) {
                return p;
            }
        }

        return null;
    }
}
